const Goods = require('../model/good.model')
class GoodsService {
    // 创建商品
    async createGoods(goods) {
        const res = await Goods.create(goods)
        return res.dataValues
    }
    // 更新商品信息
    async updateGoods(id, goods) {
        const res = await Goods.update(goods, { where: { id } })
        return res[0] > 0 ? true : false
    }
    //商品下架
    async removeGoods(id) {
        const res = await Goods.destroy({ where: { id } })
        return res > 0 ? true : false
    }
    // 恢复上架商品
    async restoreGoods(id) {
        const res = await Goods.restore({ where: { id } })
        return res > 0 ? true : false
    }
    async fingGoods(pageNum, pageSize) {
        const offset = (pageNum - 1) * pageSize
        console.log('1111' + offset)
        const { count, rows } = await Goods.findAndCountAll({
            offset: offset,
            // limit: Number(pageSize)
            limit: pageSize * 1
        })
        return {
            pageNum,
            pageSize,
            total: count,
            rows
        }

    }
}
module.exports = new GoodsService()